package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mobile.domain.UserInfoType;
import com.ruoyi.mobile.service.IUserInfoService;
import com.ruoyi.mobile.service.IUserInfoTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/mobile/questionaire")
public class QuestionaireController extends BaseController {

    @Autowired
    public IUserInfoService userInfoService;

    @Autowired
    public IUserInfoTypeService userInfoTypeService;

    @ResponseBody
    @RequestMapping("/list")
    @PreAuthorize("@ss.hasPermi('mobile:questionaire:list')")
    public TableDataInfo list(UserInfoType userInfoType) {
        startPage();
        List<UserInfoType> list = userInfoTypeService.selectUserInfoTypeList(userInfoType);
        return getDataTable(list);
    }


    /**
     * 获取调查问卷类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:questionaire:query')")
    @GetMapping(value = "/{id}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(userInfoTypeService.selectUserInfoTypeById(id));
    }

    /**
     * 新增调查问卷类型
     */
    @PreAuthorize("@ss.hasPermi('mobile:questionaire:add')")
    @Log(title = "调查问卷", businessType = BusinessType.INSERT)
    @PostMapping
    @ResponseBody
    public AjaxResult add(@RequestBody UserInfoType userInfoType)
    {
        return toAjax(userInfoTypeService.insertUserInfoType(userInfoType));
    }

    /**
     * 修改调查问卷类型
     */
    @PreAuthorize("@ss.hasPermi('mobile:questionaire:edit')")
    @Log(title = "调查问卷", businessType = BusinessType.UPDATE)
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody UserInfoType userInfoType)
    {
        return toAjax(userInfoTypeService.updateUserInfoType(userInfoType));
    }

    /**
     * 删除调查问卷类型
     */
    @PreAuthorize("@ss.hasPermi('mobile:questionaire:remove')")
    @Log(title = "调查问卷", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(userInfoTypeService.deleteUserInfoTypeByIds(ids));
    }

}
